/**
 * 2010(c) Copyright Oceansoft Information System Co.,LTD. All rights reserved.
 * <p>
 * Compile: JDK 1.6+
 * <p>
 * 版权所有(C)：江苏欧索软件有限公司
 * <p>
 * 公司名称：江苏欧索软件有限公司
 * <p>
 * 公司地址：中国苏州科技城青山路1号
 * <p>
 * 网址: http://www.oceansoft.com.cn
 * <p>
 * 作者: 090922(陈伟)
 * <p>
 * 文件名: com.oceansoft.mobile.econsole.modules.message.controller.MessageController.java 
 * <p>
 * 类产生时间: 14-5-6 下午4:45
 * <p>
 * 负责人: 090922(陈伟)
 * <p>
 * Email:javacspring@gmail.com
 * <p>
 * 所在组 : 掌上公安应用平台
 * <p>
 * 所在部门: 开发部--手持技术部
 * <p>
 * <p>
 */
package com.oceansoft.mobile.econsole.modules.message.controller;

import com.oceansoft.mobile.econsole.modules.base.controller.BaseController;
import com.oceansoft.mobile.econsole.modules.base.entity.Result;
import com.oceansoft.mobile.econsole.modules.message.entity.ExceptionCommonBase;
import com.oceansoft.mobile.econsole.modules.message.entity.PushMessage;
import com.oceansoft.mobile.econsole.modules.message.service.PushMessageService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 消息控制器
 * 
 * @author: chenw
 * @time: 14-5-6 下午4:45
 */
@Controller
@RequestMapping("message")
public class MessageController extends BaseController {

	@Resource
	private PushMessageService pushMessageService;

	@RequestMapping("index")
	public String gotoMessageIndex() {
		return "message/message-index";
	}

	@ResponseBody
	@RequestMapping(value = "send", method = RequestMethod.POST)
	public Result sendMessage(HttpServletRequest request) {
		String messageType = request.getParameter("messageType");// 推送针对人群4,2,3
		String platForm = request.getParameter("platform");
		String messageGroup = request.getParameter("messageGroup");// 组名，messageType=2时必选
		String alias = request.getParameter("alias");// 别名，messageType=3时必选
		String title = request.getParameter("title");// 消息标题
		String contentStr = request.getParameter("contentStr");// 消息内容
		String contentType = request.getParameter("contentType");// 消息类型
		String extra = request.getParameter("extra");// 扩展消息
		Result result = new Result();
		try {
			pushMessageService.saveMessage(title, PushMessage.PushType
					.lookUp(Integer.valueOf(messageType)), messageGroup, alias,
					contentStr, PushMessage.ContentType.lookUp(Integer
							.valueOf(contentType)), extra, platForm);
		} catch (Exception e) {
			e.printStackTrace();
			result.setSucc(Result.FAILURE);
			result.setMsg("信息推送失败");
			log("信息推送失败：" + contentStr);
			return result;
		}

		result.setMsg("信息推送成功");
		log("信息推送成功：" + contentStr);
		return result;
	}
}
